﻿//========================================================= 
/**@file SdtApiCmdDriver.h
 * @brief SDTAPI接口命令驱动
 * 
 * @date 2017-06-19   23:40:09
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_SDTAPICMDDRIVER_H_
#define _LIBZHOUYB_SDTAPICMDDRIVER_H_
//--------------------------------------------------------- 
#include "../CommonCmdDriver.h"

#include <application/idcard/IDCardDevAdapter.h>
using zhou_yb::application::idcard::IDCardDevAdapter;
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace driver {
//--------------------------------------------------------- 
/**
 * @brief SDTAPI接口命令驱动
 * @date 2017-06-19 23:41:28
 */
class SdtApiCmdDriver : 
    public CommonCmdDriver, 
    public BaseDevAdapterBehavior<IInteractiveTrans>
{
protected:
    Ref<ISdtApi> _refSdtApi;
    IDCardDevAdapter _idAdapter;
    SdtApiDevAdapter _sdtapiAdapter;
public:
    SdtApiCmdDriver() : CommonCmdDriver()
    {
        _errGetter.Add(_sdtapiAdapter);

        _sdtapiAdapter.SelectDevice(_idAdapter);
        _logSetter.select(_sdtapiAdapter);

        _refSdtApi = _sdtapiAdapter;

        // 默认不开启
        _idAdapter.SetWaitTimeout(0);
        _idAdapter.SetOperatorInterval(0);

        _RegisteCMD(SdtApiCmdDriver, SetDelayTimeout);

        _RegisteExceptCMD(SdtApiCmdDriver);
        _RegisteInterfaceCMD(SdtApiCmdDriver, ISdtApi);
        _RegisteAdapterCMD(SdtApiCmdDriver);
    }
    LC_CMD_INTERFACE_GETTER(ISdtApi, _refSdtApi);
    LC_CMD_ADAPTER_INVOKE(IInteractiveTrans, _idAdapter);
    LC_CMD_EXCEPT()
    {
        EXCEPT_CMD(SetDelayTimeout);
        return true;
    }
    /**
     * @brief 设置IDC指令延时
     * @date 2016-10-23 21:12
     *
     * @param [in] Timeout : uint 读卡指令延时
     * @param [in] Interval : uint 读卡指令轮询间隔
     */
    LC_CMD_METHOD(SetDelayTimeout)
    {
        string sTimeoutMs;
        if(arg.Get("Timeout", sTimeoutMs))
        {
            _idAdapter.SetWaitTimeout(ArgConvert::FromString<uint>(sTimeoutMs));
        }
        sTimeoutMs = "";
        if(arg.Get("Interval", sTimeoutMs))
        {
            _idAdapter.SetOperatorInterval(ArgConvert::FromString<uint>(sTimeoutMs));
        }
        return true;
    }
};
//--------------------------------------------------------- 
} // nemespace driver
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_SDTAPICMDDRIVER_H_
//========================================================= 